#! /usr/bin/python

import types
indent = 0
def printBases(clsobj):
    if hasattr(clsobj, "__class__"):
        return printBases(clsobj.__class__)
    elif type(clsobj)!=types.ClassType:
        raise "must input a class object as an argument"

    global indent
    print " "*indent+str(clsobj)
    indent += 2
    for b in clsobj.__bases__:
        printBases(b)
    indent -= 2

if __name__ == "__main__":
    import class_test
    printBases(class_test.SClass)
    b = class_test.SClass()
    printBases(b)

s = "abc"
it = iter(s)
print it
try:
    while True:
        print it.next()
except StopIteration:
    print "end of the iteration"

def reverse(data):
    for idx in range(len(data)-1, -1, -1):
        yield data[idx]

for k in reverse("hello world"):
    print k

#static method and class method
class testClass (object):
    #the  construction method
    #_singletons = { }
    #def __new__(cls, *args, **kwds):
        #if not _singletons.has_key(cls):
            #_singletons[cls] = object.__new__(cls)
        #return _singletons[cls]

    def astaticmethod():
        print "a static methon"
    #create a static method
    astaticmethod = staticmethod(astaticmethod);
    def aclassmet(cls):
        print "a class method for",cls.__name__
    #use class object as the first argument
    aclassmet = classmethod(aclassmet)



testClass.astaticmethod()
testClass.aclassmet()

from UserList import *
try:
    raise UserList([1,2,3])
except UserList,arg:
    for k in arg:
        print k
a = testClass()
if isinstance(a, testClass):
    print "a is testclass instance"

code = "print 'hello world'"
c = complie(code, "abc", "exec")
profile.run("for i in range(10000): exec c")
